package com.senseilearning.sensei;

import java.util.ArrayList;
import java.util.Random;


public class Question {
	public String[][] questions = { { "1", "2", "3", "4" },
			{ "A", "B", "C", "D" } };
	Section section;

	Spacer spacer;
	ArrayList<Word> words = new ArrayList<Word>();
	int index;
	int q;
	boolean use_spacing;
	boolean [] switchlanguage;
	
	public Question(Section section, Spacer spacer) {
		
		this.section = section;
		this.spacer = spacer;
		words = section.getWords();
		switchlanguage = new boolean[words.size()];
		
		index = 0;
		use_spacing = true;
	}

	public Question(int chapter_number, Section section,
			Spacer spacer, Boolean use_spacing) {
		
		
		this.section = section;
		this.spacer = spacer;
		words = section.getWords();
		switchlanguage = new boolean[words.size()];
		
		
		index = 0;
		this.use_spacing = use_spacing;
	}

	public String[][] getQuestions() {
		return questions;
	}

	// true als woord nieuw is.
	public boolean nextQuestion() {
		// moet via SpacingMethods.java een nieuwe vraag ophalen

		if (words.size() == 0) {
			return false;
		}

		ArrayList<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < words.size(); i++) {
			list.add(i);
		}

		if (use_spacing) {
			q = spacer.determineNextPair();
		} else {
			Random rand = new Random();
			q = rand.nextInt(words.size());
		}
		questions[0][0] = words.get(list.get(q)).getWord1();
		questions[1][0] = words.get(list.get(q)).getWord2();
		
		switchlanguage[q] = !switchlanguage[q];
		
		
		if (!use_spacing) {
			words.remove(q);
		} else {
			list.remove(q);
			for (int i = 1; i < 4; i++) {
				int random = (int) (Math.random() * list.size());
				questions[0][i] = words.get(list.get(random)).getWord1();
				questions[1][i] = words.get(list.get(random)).getWord2();
				list.remove(random);
			}
		}
		
		
		return switchlanguage[q];
	}
	


}